/*function getTypeName(name) {
    if(name==0){
        return "个人";
    }else if(name==1){
        return "公司";
    }else if(name==2){
        return "管理员"
    }
}*/
window.onload = function(){
    var index = parent.layer.getFrameIndex(window.name);
    var url = window.location.search;//你的地址

    if (url.indexOf("?") != -1) {
        var str = url.substr(1)
        strs = str.split("&");
        var page = strs[0].split("=")[1];
    }
    console.log(page);
    $.ajax({
        url:constUrl+"RoleServlet",
        type:'post',
        data:{
            operateType:"showDetail",
            roleId:page
        },
        dataType:'json',
        success: function(responseText) {
            console.log(responseText.result);
            $("#name").val(responseText.result.role.name);
            $("#introduction").val(responseText.result.role.introduction);
            //显示权限功能
            var usercode=responseText.result.role.powerCode;
            var code=usercode.split("#");
            for(var i=0;i<code.length;i++){
                console.log(code[i]);
                var temp = code[i].substr(code[i].length-1,1);
                $("#code_"+temp).attr("checked",true);
            }

        },
        complete: function() {
        },
        error: function() {
        }
    });

    $('#updateCharacter').click(function () {
        var name = $("#name").val();
        var introduction = $("#introduction").val();
        var userCode="";
        var temp="";
/*        for(var i=1;i<8;i++){
            if(document.getElementById("code_"+i).checked==true){
                userCode=userCode+temp+$("#code_"+i).val();
                temp="#";
            }
        }*/
        
        userCode = $('input[type="checkbox"][name="code"]:checked').map(function () {
            return $(this).val();
        }).get().join("#");


        if(name==""||introduction==""||userCode==""){
            parent.layer.confirm('关键信息未填，不能修改！',{btn:['确定']});
        }else {
            $.ajax({
                url: constUrl + "RoleServlet",
                type: 'post',
                data: {
                    operateType: "alter",
                    name: name,
                    introduction: introduction,
                    id:page,
                    power_code:userCode
                },
                dataType: 'json',
                success: function (dataText) {
                    console.log(dataText.result);
                    if (dataText.result) {
                        parent.layer.confirm('修改成功！', {
                            btn: ['确定']
                        }, function () {
                            parent.location.reload(index);
                            parent.layer.close(index);

                        })

                    }
                },
                complete: function () {
                },
                error: function () {

                }
            });
        }
    });
    $('#closeIframe').click(function(){
        parent.layer.close(index);
    });
}
